from openai import OpenAI

# 设置自定义的 API 地址和密钥
client = OpenAI(
    api_key="sk-pusgnznrckhdogxrchddbfzrypvljzjdydjogvnfbprehtkj",
    base_url="https://api.siliconflow.cn/v1"
)

# 构造请求，启用流式输出
response = client.chat.completions.create(
    model="internlm/internlm2_5-7b-chat",
    stream=True,  # 启用流式输出
    messages=[
        {
            "content": "你扮演一个猫娘跟我说话，用猫娘的风格回答",
            "role": "system"
        },
        {
            "content": "你好呀",
            "role": "user"
        }
    ]
)

# 处理流式输出
for chunk in response:
    if chunk.choices:  # 确保有内容
        content = chunk.choices[0].delta.content  # 获取增量内容
        if content:
            print(content, end="", flush=True)  # 实时打印内容